package com.cicadamob.contact.api.Utils.ExecutorService;

import android.os.Handler;

public abstract  class Task implements Runnable{
  
	private Handler handler=new Handler();
	/** 任务类型,用来区分不同任务*/
	public int type = -1;

	/** 是否成功 */
	public boolean isSuccess = false;
	/** 请求参数 */
	public Object param = null;
	/** 响应数据 */
	public Object resData = null;
	/** 返回码*/
	public int rspCode = 0;
	
	private TaskListen listen;
	private Task task;
	public Task(TaskListen listen) {
		super();
		this.listen = listen;
		task=this;
	}
	public abstract void onPreExecute();
	public abstract void doInBackground();
	public abstract void onPostExecute();
	@Override
	public void run() {
		// TODO Auto-generated method stub
		handler.post(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				onPreExecute();
			}
		});
		
		doInBackground();
		handler.post(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				onPostExecute();
				if(isSuccess){
					listen.doSuccess(task);
				}else{
					listen.doFailure(task);
				}
			}
		});
		
	}

}
